//
//  SearchBar.m
//  pmm
//
//  Created by WTFSSD on 2017/7/26.
//  Copyright © 2017年 WTFSSD. All rights reserved.
//

#import "SearchBar.h"
//#import "AreaPickerViewController.h"

@interface SearchBar()
@property (weak, nonatomic) IBOutlet UIButton *leftButton;
@property (weak, nonatomic) IBOutlet UITextField *textField;


@property(nonatomic,strong)id target;

@property(nonatomic,assign)SEL select;

@property(nonatomic,strong)UITapGestureRecognizer * ges;


@property(nonatomic,strong)WEPopoverController * pop;
@end
IB_DESIGNABLE
@implementation SearchBar




-(void)awakeFromNib{

    [super awakeFromNib];
    self.editEnable = YES;
    self.textField.enabled = YES;
//    self.pop = [[WEPopoverController alloc] initWithContentViewController:[[AreaPickerViewController alloc] init]];
//    self.pop.animationType = WEPopoverAnimationTypeSlide;
//    self.pop.popoverContentSize = CGSizeMake(SCREEN_WIDTH, 400);
//    
//    self.pop.backgroundColor = RGBA(0, 0, 0, 0.5);
//    
//    self.pop.popoverLayoutMargins = UIEdgeInsetsZero;
//    self.pop.containerViewProperties = [WEPopoverController defaultContainerViewProperties];
//    self.pop.containerViewProperties.contentMargins = UIEdgeInsetsZero;
//    self.pop.containerViewProperties.backgroundMargins = UIEdgeInsetsMake(44, 0, 0, 0);
//    self.pop.containerViewProperties.upArrowImageName = @"icon_arrow_up_solid_white";

}


-(void)addClickTarget:(id)targe select:(SEL)select{
    self.target = targe;
    self.select = select;
    self.ges = [[UITapGestureRecognizer alloc] initWithTarget:self.target action:self.select];
   [self addGestureRecognizer:self.ges];
}

-(void)setPlaceholder:(NSString *)placeholder{
    _placeholder = placeholder;
    NSMutableAttributedString * ms = [[NSMutableAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName:[UIColor lightGrayColor]}];
    self.textField.attributedPlaceholder = ms;
}

-(void)setEditEnable:(BOOL)editEnable{
    self.textField.enabled = editEnable;
}

- (IBAction)leftButtonClick:(UIButton *)sender {
    [self.pop presentPopoverFromRect:sender.frame inView:self permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.layer.borderWidth = 1.f;
    self.layer.cornerRadius = 8.0f;
    self.layer.borderColor = RGBA(255, 255, 255, 1).CGColor;
    if (self.editEnable) {
        [self removeGestureRecognizer:self.ges];
    }
}

-(void)becomeFirstResponder{
    [self.textField becomeFirstResponder];
}

-(void)resignFirstResponder{
    [self.textField resignFirstResponder];
}


@end
